# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=fontconfig

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.11.1
pkgrel=1
pkgdesc="A library for configuring and customizing font access (mingw-w64)"
arch=('any')
url="http://www.fontconfig.org/release"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-expat>=2.1.0"
    "${MINGW_PACKAGE_PREFIX}-freetype>=2.3.11"
    "${MINGW_PACKAGE_PREFIX}-bzip2>=1.0.6"
    "${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' 'strip')
install=${_realname}-${CARCH}.install
source=("http://www.fontconfig.org/release/fontconfig-$pkgver.tar.bz2"
    "fontconfig-2.11.0-symlinks-fix.patch")
sha256sums=('dc62447533bca844463a3c3fd4083b57c90f18a70506e7a9f4936b5a1e516a99'
            '92541375e945261832d4876551f94596fcf540c4edaf789ac0f36de7592c5966')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fontconfig-2.11.0-symlinks-fix.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-iconv \
    --disable-docs \
    --with-arch=${CARCH} \
    as_ln_s="cp -pR"
  sed -i 's,all-am: Makefile $(PROGRAMS),all-am:,' test/Makefile
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
